/**
 * fileName:com.baidu.inf.iis.bcs.handler.ObjectListResponseHandler.java
 * projectName:Zimo
 */
package com.baidu.inf.iis.bcs.handler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import com.baidu.inf.iis.bcs.http.BCSHttpResponse;
import com.baidu.inf.iis.bcs.model.ObjectListing;
import com.baidu.inf.iis.bcs.model.ObjectSummary;
import com.baidu.inf.iis.bcs.response.BaiduBCSResponse;

import flexjson.JSONDeserializer;

/**
 * 百度云存储包有错误，我给反编译，修改了，自己建的类，覆盖百度sdk包里的class
 * @author sg.z/2013-12-23/上午10:49:16
 */
public class ObjectListResponseHandler extends HttpResponseHandler<ObjectListing>
 {
   public BaiduBCSResponse<ObjectListing> handle(BCSHttpResponse paramBCSHttpResponse)
   {
     String str = getResponseContentByStr(paramBCSHttpResponse);
     JSONDeserializer localJSONDeserializer = new JSONDeserializer();
     HashMap localHashMap1 = (HashMap)localJSONDeserializer.deserialize(str);
 
     ObjectListing localObjectListing = new ObjectListing();
 
     localObjectListing.setObjectTotal(((Long)localHashMap1.get("object_total")).intValue());
 
     if (localHashMap1.get("start") instanceof String)
       localObjectListing.setStart(Integer.valueOf((String)localHashMap1.get("start")).intValue());
     else {
       localObjectListing.setStart(((Long)localHashMap1.get("start")).intValue());
     }
 
     if (localHashMap1.get("limit") instanceof String)
       localObjectListing.setLimit(Integer.valueOf((String)localHashMap1.get("limit")).intValue());
     else {
       localObjectListing.setLimit(((Long)localHashMap1.get("limit")).intValue());
     }
 
     localObjectListing.setBucket((String)localHashMap1.get("bucket"));
 
     if (localHashMap1.get("prefix") != null) {
       localObjectListing.setPrefix((String)localHashMap1.get("prefix"));
     }
 
     ArrayList localArrayList = (ArrayList)localHashMap1.get("object_list");
     for (Object localObject = localArrayList.iterator(); ((Iterator)localObject).hasNext(); ) {
       HashMap localHashMap2 = (HashMap)((Iterator)localObject).next();
       ObjectSummary localObjectSummary = new ObjectSummary();
       localObjectSummary.setName((String)localHashMap2.get("object"));
       localObjectSummary.setVersionKey((String)localHashMap2.get("version_key"));
       localObjectSummary.setIsDir(((String)localHashMap2.get("is_dir")).equals("1"));
       localObjectSummary.setSize(Long.valueOf((String)localHashMap2.get("size")));
       localObjectSummary.setLastModifiedTime(Long.valueOf((String)localHashMap2.get("mdatetime")));
       localObjectSummary.setParentDir((String)localHashMap2.get("parent_dir"));
       localObjectListing.addObjectSummary(localObjectSummary);
     }
     BaiduBCSResponse<ObjectListing> localObject2 = parseResponseMetadata(paramBCSHttpResponse);
     localObject2.setResult(localObjectListing);
     return localObject2;
   }
 }
